package org.dubnation.auth.controller;

import org.dubnation.auth.service.IRoleMenuService;
import org.dubnation.auth.domain.RoleMenu;
import org.dubnation.auth.query.RoleMenuQuery;
import org.dubnation.base.util.AjaxResult;
import org.dubnation.base.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/roleMenu")
public class RoleMenuController {
    @Autowired
    public IRoleMenuService roleMenuService;


    /**
     * 保存和修改公用的
     * @param roleMenu  传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping
    public AjaxResult insertOrUpdate(@RequestBody RoleMenu roleMenu){
        if( roleMenu.getId()!=null)
            roleMenuService.update(roleMenu);
        else
            roleMenuService.insert(roleMenu);
        return AjaxResult.me();
    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        roleMenuService.delete(id);
        return AjaxResult.me();
    }
	
    //获取用户
    @GetMapping("/{id}")
    public AjaxResult queryById(@PathVariable("id")Long id) {
        RoleMenu roleMenu = roleMenuService.queryById(id);
        return AjaxResult.me().setData(roleMenu);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping
    public AjaxResult queryAll(){
        List< RoleMenu> list = roleMenuService.queryAll();
        return AjaxResult.me().setData(list);
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping
    public AjaxResult queryPage(@RequestBody RoleMenuQuery query) {
        PageInfo<RoleMenu> pageInfo = roleMenuService.queryPage(query);
        return AjaxResult.me().setData(pageInfo);
    }

    /**
    * 批量删除数据
    * @param ids
    * @return
*/
    @PatchMapping
    public AjaxResult batchDelete(@RequestBody List<Long> ids) {
        roleMenuService.batchDelete(ids);
        return AjaxResult.me();
    }
}
